home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_12 / guthrie2 / currency.c < prev    next >
C/C++ Source or Header  |  1994-01-22  |  2KB  |  52 lines

  1. /* CURRENCY.C - Demonstration application for Currency Formatting. */
  2. /* Written by: R. Scott Guthrie                                    */
  3. /* Requires XLATE functions and translate file entries for         */
  4. /*  "Our Currency", "Alt Currency 1", and "Alt Currency 2"         */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "xlate.h"
  10.  
  11. void main()
  12. {
  13.   char format[80];      /* Constructed format string buffer */
  14.  
  15.   /* The next two values represent the value of each 'Alt Currency' */
  16.   /* unit to each unit of 'Our Currency'.                           */
  17.   /* These values must be loaded at run time since the conversion   */
  18.   /* rates for currency values is dynamic, but sample data is       */
  19.   /* directly assigned for demonstration purposes here.             */
  20.   float AltCurrency1 = 0.6;
  21.   float AltCurrency2 = 1.4;
  22.  
  23.   float Amount = 2.8;   /* Amount of 'Our Currency' to be converted */
  24.  
  25.   XlateSet("CURRENCY");
  26.  
  27.   /* Build the format string */
  28.   strcpy(format, "%5.2f ");
  29.   strcat(format, Xlate("Our Currency"));
  30.   strcat(format, " = %5.2f ");
  31.   strcat(format, Xlate("Alt Currency 1"));
  32.   strcat(format, "\n");
  33.  
  34.   /* Print Our Currency and the value of the Alternate Currency */
  35.   printf(format, Amount, Amount * AltCurrency1);
  36.  
  37.   /* Again for the second alternate currency... */
  38.   /* Build the format string */
  39.   strcpy(format, "%5.2f ");
  40.   strcat(format, Xlate("Our Currency"));
  41.   strcat(format, " = %5.2f ");
  42.   strcat(format, Xlate("Alt Currency 2"));
  43.   strcat(format, "\n");
  44.  
  45.   /* Print Our Currency and the value of the Alternate Currency */
  46.   printf(format, Amount, Amount * AltCurrency2);
  47.  
  48.   /* Free Translate Table memory */
  49.   XlateFree();
  50. }
  51. /* end source file CURRENCY.C */
  52.